#! /usr/bin/env node

const fs = require('fs')
const path = require('path')
const inquirer = require('inquirer') //获取用户输入
const ejs = require('ejs')

inquirer.prompt([
    {
        type:'input',
        name:'title',
        message:'Your Project name',
        default:this.appname
    },
    {
        type:'input',
        name:'desc',
        message:'Your Project description'
    },

]).then(answers=>{
    // 获取模板路径
    const tempDir = path.join(__dirname,'templates');
    // 目标路径
    const destDir = process.cwd();
    fs.readdir(tempDir,(err,files)=>{
        if(err) throw err
        files.forEach(file => {
            console.log(file);
            ejs.renderFile(path.join(tempDir,file),answers,(err,result)=>{
                if(err) throw err
                fs.writeFileSync(path.join(destDir,file),result)
            })
        });

    })


})